import React, { Component } from 'react';
import css from './index.less';
import FilterSearch from '@/components/FilterSearch';
import TableList from '@/components/TableList';
import EditModal from '@/components/EditModal';
import { Button, Divider } from 'antd';
import { connect } from 'dva';
import { timeFormat } from '@/utils/common';
import { Link } from 'react-router-dom';
import AuthButton from '@/components/AuthButton';
import Status from '@/pages/components/Status';

type State = {
  selectProject: any;
};
type Props = {
  dispatch: Function;
};
class Department extends Component<Props> {
  state: State = {
    selectProject: {},
  };
  table = null;

  filters = [
    {
      key: 'serviceTypeUuid',
      type: 'select',
      label: '项目类型',
      asyncopt: {
        url: '/api/data/v1/getDataList',
        data: {
          code: 'service',
        },
      },
    },
    {
      key: 'budget',
      type: 'select',
      label: '投资概算',
      options: this.props.dict.budget,
    },
    {
      key: 'examineStatus',
      type: 'select',
      label: '评审状态',
      options: this.props.dict.approveStatus,
    },
    {
      key: 'no',
      type: 'input',
      label: '项目ID',
    },
    {
      key: 'examineOrgName',
      type: 'input',
      label: '评审机构',
    },
    {
      key: 'name',
      type: 'input',
      label: '项目名称',
    },
  ];
  columns = [
    { title: '项目ID', dataIndex: ['project', 'no'] },
    {
      title: '项目名称',
      dataIndex: ['project', 'name'],
      render: (text, data) => (
        <Button type="link" onClick={() => this.goDetail(data, true)}>
          {text}
        </Button>
      ),
    },
    {
      title: '报送日期',
      dataIndex: ['project', 'createTime'],
      format: 'YYYY-MM-DD',
      render: text => timeFormat(text, 'YYYY-MM-DD'),
    },
    {
      title: '项目类型',
      dataIndex: ['project', 'serviceTypeData', 'display'],
    },
    { title: '投资概算（万元）', dataIndex: ['project', 'totalInvestment'] },
    { title: '业主单位', dataIndex: ['project', 'ownerOrgUnit', 'name'] },
    {
      title: '评审增减（万元）',
      dataIndex: ['examineRecordVO', 'changeAmount'],
    },
    {
      title: '评审状态',
      dataIndex: 'examineRecordVO',
      render: (text, data) =>
        text ? '已评审' : <span style={{ color: '#327CEC' }}>待评审</span>,
    },
    {
      title: '操作',
      dataIndex: 'uuid',
      width: 150,
      render: (uuid, project) => {
        return project.examineRecordVO ? (
          ''
        ) : (
          <AuthButton
            type="link"
            onClick={() => this.goApproveDetail(uuid)}
            role="registe_examine_info"
          >
            登记评审信息
          </AuthButton>
        );
      },
    },
  ];

  goApproveDetail = id => {
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url: 'projectManage/projectReview/edit?id=' + id,
      },
    });
  };
  goDetail = (data: any, readOnly: boolean) => {
    const url = `projectFillIn/scheme/edit?id=${data.uuid ||
      ''}&readOnly=${readOnly || ''}`;
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url,
      },
    });
  };
  render() {
    const { selectProject } = this.state;
    return (
      <div>
        <FilterSearch
          filters={this.filters}
          onSearch={val => this.table.fetch(val)}
        ></FilterSearch>
        <TableList
          post
          rowKey="id"
          onRef={c => {
            this.table = c;
          }}
          columns={this.columns}
          source="/api/scheme/v1/query"
        />
      </div>
    );
  }
}

export default connect(state => state.base)(Department);
